package com.cc.springboot_test.converter;

import com.cc.springboot_test.utils.DateUtils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.InjectableValues;
import com.fasterxml.jackson.databind.deser.DefaultDeserializationContext;
import com.fasterxml.jackson.databind.deser.DeserializerCache;
import com.fasterxml.jackson.databind.deser.DeserializerFactory;

import java.util.Date;

/**
 * 用于post参数请求形式的日期格式转换（重写parseDate方法）
 */
public class PostDeserializationContext extends DefaultDeserializationContext {


    protected PostDeserializationContext(DeserializerFactory src) {
        super(src, null);
    }

    protected PostDeserializationContext(PostDeserializationContext df) {
        super(df);
    }

    protected PostDeserializationContext(PostDeserializationContext src, DeserializationConfig config, JsonParser jp, InjectableValues values) {
        super(src, config, jp, values);
    }

    protected PostDeserializationContext(PostDeserializationContext src, DeserializerFactory factory) {
        super(src, factory);
    }


    @Override
    public DefaultDeserializationContext with(DeserializerFactory deserializerFactory) {
        return new PostDeserializationContext(this, deserializerFactory);
    }

    @Override
    public DefaultDeserializationContext createInstance(DeserializationConfig deserializationConfig, JsonParser jsonParser, InjectableValues injectableValues) {
        return new PostDeserializationContext(this, deserializationConfig, jsonParser, injectableValues);
    }

    @Override
    public DefaultDeserializationContext copy() {
        if (getClass() != PostDeserializationContext.class) {
            return super.copy();
        } else {
            return new PostDeserializationContext(this);
        }
    }

    @Override
    public Date parseDate(String dateStr) throws IllegalArgumentException {
        return DateUtils.dateToTimestamp(dateStr, DateUtils.DATE_FULL_STR, DateUtils.DATE_MID_STR, DateUtils.DATE_SMALL_STR);
    }
}
